{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Using Q\\# with Python"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Abstract"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This notebook shows how to use Q# and Python together to develop and simulate quantum programs with the Quantum Development Kit."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## The `qsharp` package"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We begin by importing the `qsharp` Python package. This package provides Q# interoperability for Python, as well as integration with Jupyter."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Preparing Q# environment...\n",
      "..."
     ]
    }
   ],
   "source": [
    "import qsharp"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Once imported, the `qsharp` package exposes Q# functions and operations as Python objects that we can use to simulate quantum programs, estimate quantum resources, and so forth.\n",
    "\n",
    "Let's start by defining a new Q# operation with the `%%qsharp` magic command."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "%%qsharp\n",
    "\n",
    "operation SayHello(name : String) : Unit {\n",
    "    Message($\"Hello, {name}!\");\n",
    "}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This creates a new Python object `SayHello` that represents our new Q# operation."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Q# callable SayHello>"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "SayHello"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "By using the `.simulate` method, we can run our new operation on a quantum simulator:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Hello, quantum world!\r\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "()"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "SayHello.simulate(name=\"quantum world\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Inputs to your Q# operation are represented by Python keyword arguments, and outputs are returned back to the Python host."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "%%qsharp\n",
    "\n",
    "function Plus(x : Int, y : Int) : Int {\n",
    "    return x + y;\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "8"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Plus.simulate(x=3, y=5)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Of course, you can also use qubits in the Q# programs that you simulate from Python:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "%%qsharp\n",
    "open Microsoft.Quantum.Measurement;\n",
    "\n",
    "operation SampleQrng() : Result {\n",
    "    use q = Qubit();\n",
    "    H(q);\n",
    "    return MResetZ(q);\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "SampleQrng.simulate()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The `qsharp` package also provides the `compile` function, which allows for compiling Q# code from Python strings."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "sample_qrng = qsharp.compile(\"\"\"\n",
    "    operation SampleQrng() : Result {\n",
    "        use q = Qubit();\n",
    "        H(q);\n",
    "        return MResetZ(q);\n",
    "    }\n",
    "\"\"\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sample_qrng.simulate()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Workspaces, Projects, and Packages"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n",
    "As your quantum programs get larger, it can be inconvienent to keep all of your Q# code in a single notebook or Python script. Instead, the `qsharp` package allows you to call into Q# code from source code in the same directory as your notebook.\n",
    "\n",
    "For example, in the cell below, `PrepareBellPair` is defined in [`./Operations.qs`](./Operations.qs), but we can call it from Q# operations defined using `%%qsharp`."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "%%qsharp\n",
    "open Microsoft.Quantum.Samples;\n",
    "\n",
    "operation PrepareAndMeasureBellPair() : (Result, Result) {\n",
    "    use left = Qubit();\n",
    "    use right = Qubit();\n",
    "\n",
    "    PrepareBellPair(left, right);\n",
    "    return (MResetZ(left), MResetZ(right));\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(0, 0)"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "PrepareAndMeasureBellPair.simulate()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n",
    "After importing the `qsharp` package, you can also import Q# namespaces as though they were Python packages. For example, `Operations.qs` also defines an operation that demonstrates how to run quantum teleportation; we can import it here and run the `RunTeleportationExample` operation on our simulator."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "from Microsoft.Quantum.Samples import RunTeleportationExample"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Teleported successfully!\r\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "()"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "RunTeleportationExample.simulate()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The Q# code in your workspace can also depend on other Q# _packages_ and _projects_ by using project files.\n",
    "\n",
    "> **TIP**: If you don't have a project file for your workspace, the `qsharp` package will assume some reasonable defaults. Having a project file makes it easy to use additional packages, to get code completion and hover documentation while you edit your Q# files, and so forth.\n",
    "\n",
    "For example, this sample includes a Q# project file that tells the `qsharp` Python package what other Q# packages are needed to run your code."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<!-- This line declares that the project is a Q# project, built using the\n",
      "     Microsoft.Quantum.Sdk package. -->\n",
      "<Project Sdk=\"Microsoft.Quantum.Sdk/0.24.210930\">\n",
      "\n",
      "  <PropertyGroup>\n",
      "    <OutputType>Library</OutputType>\n",
      "    <TargetFramework>net6.0</TargetFramework>\n",
      "    <!-- This property tells the qsharp package to automatically load\n",
      "         your project and use it as a workspace. -->\n",
      "    <IQSharpLoadAutomatically>true</IQSharpLoadAutomatically>\n",
      "  </PropertyGroup>\n",
      "\n",
      "  <!-- To include functions and operations from other Q# packages, you can\n",
      "       add them as package references in your project file. These packages\n",
      "       will automatically be downloaded from nuget.org and made available to your\n",
      "       Q# workspace. -->\n",
      "  <ItemGroup>\n",
      "    <PackageReference Include=\"Microsoft.Quantum.Numerics\" Version=\"0.24.210930\" />\n",
      "  </ItemGroup>\n",
      "\n",
      "</Project>\n",
      "\n"
     ]
    }
   ],
   "source": [
    "with open('python.csproj') as f:\n",
    "    print(f.read())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "To see what packages are currently added to your workspace, you can use the `qsharp.packages` object:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/json": "{\"LastUpdated\":\"2022-06-27T10:36:16.1334125-07:00\",\"IsCompleted\":false,\"Description\":\"Adding package \",\"Subtask\":null}",
      "text/plain": [
       "Adding package ."
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "[('Microsoft.Quantum.Standard', LooseVersion ('0.24.216242-beta')), ('Microsoft.Quantum.Standard.Visualization', LooseVersion ('0.24.216242-beta')), ('Microsoft.Quantum.Numerics', LooseVersion ('0.24.216242-beta'))]"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "qsharp.packages"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "You can also add new packages dynamically by using `qsharp.packages.add`:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/json": "{\"LastUpdated\":\"2022-06-27T10:36:16.161073-07:00\",\"IsCompleted\":false,\"Description\":\"Adding package Microsoft.Quantum.Chemistry\",\"Subtask\":null}",
      "text/plain": [
       "Adding package Microsoft.Quantum.Chemistry."
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "qsharp.packages.add('Microsoft.Quantum.Chemistry')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/json": "{\"LastUpdated\":\"2022-06-27T10:36:29.0600652-07:00\",\"IsCompleted\":false,\"Description\":\"Adding package \",\"Subtask\":null}",
      "text/plain": [
       "Adding package ."
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "[('Microsoft.Quantum.Standard', LooseVersion ('0.24.216242-beta')), ('Microsoft.Quantum.Standard.Visualization', LooseVersion ('0.24.216242-beta')), ('Microsoft.Quantum.Numerics', LooseVersion ('0.24.216242-beta')), ('Microsoft.Quantum.Chemistry', LooseVersion ('0.24.216242-beta'))]"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "qsharp.packages"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Diagnostics"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Just as with Q# standalone notebooks, you can also use diagnostics like `DumpMachine` and `DumpOperation` from Python notebooks to learn how your Q# program work and to help diagnose issues and bugs in your Q# programs."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "%%qsharp\n",
    "open Microsoft.Quantum.Diagnostics;\n",
    "\n",
    "operation DumpPlusState() : Unit {\n",
    "    use q = Qubit();\n",
    "    within {\n",
    "        H(q);\n",
    "    } apply {\n",
    "        DumpMachine();\n",
    "    }\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/json": "{\"diagnostic_kind\":\"state-vector\",\"qubit_ids\":[0],\"n_qubits\":1,\"amplitudes\":{\"0\":{\"Real\":0.7071067811865476,\"Imaginary\":0.0,\"Magnitude\":0.7071067811865476,\"Phase\":0.0},\"1\":{\"Real\":0.7071067811865476,\"Imaginary\":0.0,\"Magnitude\":0.7071067811865476,\"Phase\":0.0}}}",
      "text/html": [
       "\r\n",
       "                    <table style=\"table-layout: fixed; width: 100%\">\r\n",
       "                        <thead>\r\n",
       "                            \r\n",
       "                        <tr>\r\n",
       "                            <th>Qubit IDs</th>\r\n",
       "                            <td span=\"3\">0</td>\r\n",
       "                        </tr>\r\n",
       "                    \r\n",
       "                            <tr>\r\n",
       "                                <th style=\"width: 20ch)\">Basis state (little endian)</th>\r\n",
       "                                <th style=\"width: 20ch\">Amplitude</th><th style=\"width: calc(100% - 26ch - 20ch)\">Meas. Pr.</th><th style=\"width: 6ch\">Phase</th>\r\n",
       "                            </tr>\r\n",
       "                        </thead>\r\n",
       "                        <tbody>\r\n",
       "                        \r\n",
       "                            <tr>\r\n",
       "                                <td>$\\left|0\\right\\rangle$</td>\r\n",
       "                                <td>$0.7071 + 0.0000 i$</td>\r\n",
       "                                \r\n",
       "                                <td>\r\n",
       "                                    <progress\r\n",
       "                                        max=\"100\"\r\n",
       "                                        value=\"50.000000000000014\"\r\n",
       "                                        style=\"width: 100%;\"\r\n",
       "                                    > \r\n",
       "                                    <td>\r\n",
       "                                    <p id=\"round-fb6d3a59-c5f1-4ebc-b5a7-da4bf04155d5\"> \r\n",
       "                                    <script>\r\n",
       "                                    var num = 50.000000000000014;\r\n",
       "                                    num = num.toFixed(4);\r\n",
       "                                    var num_string = num + \"%\";\r\n",
       "                                     document.getElementById(\"round-fb6d3a59-c5f1-4ebc-b5a7-da4bf04155d5\").innerHTML = num_string;\r\n",
       "                                    </script> </p>\r\n",
       "                                    </td>\r\n",
       "                                </td>\r\n",
       "                            \r\n",
       "                                \r\n",
       "                                <td style=\"transform: rotate(0deg);\r\n",
       "                   text-align: center;\">\r\n",
       "                                 ↑\r\n",
       "                                </td>\r\n",
       "                            \r\n",
       "                            </tr>\r\n",
       "                        \n",
       "\r\n",
       "                            <tr>\r\n",
       "                                <td>$\\left|1\\right\\rangle$</td>\r\n",
       "                                <td>$0.7071 + 0.0000 i$</td>\r\n",
       "                                \r\n",
       "                                <td>\r\n",
       "                                    <progress\r\n",
       "                                        max=\"100\"\r\n",
       "                                        value=\"50.000000000000014\"\r\n",
       "                                        style=\"width: 100%;\"\r\n",
       "                                    > \r\n",
       "                                    <td>\r\n",
       "                                    <p id=\"round-a77772a7-7332-47c5-b7e5-4c2c3f79a9e0\"> \r\n",
       "                                    <script>\r\n",
       "                                    var num = 50.000000000000014;\r\n",
       "                                    num = num.toFixed(4);\r\n",
       "                                    var num_string = num + \"%\";\r\n",
       "                                     document.getElementById(\"round-a77772a7-7332-47c5-b7e5-4c2c3f79a9e0\").innerHTML = num_string;\r\n",
       "                                    </script> </p>\r\n",
       "                                    </td>\r\n",
       "                                </td>\r\n",
       "                            \r\n",
       "                                \r\n",
       "                                <td style=\"transform: rotate(0deg);\r\n",
       "                   text-align: center;\">\r\n",
       "                                 ↑\r\n",
       "                                </td>\r\n",
       "                            \r\n",
       "                            </tr>\r\n",
       "                        \r\n",
       "                        </tbody>\r\n",
       "                    </table>"
      ],
      "text/plain": [
       "|0⟩\t0.7071067811865476 + 0𝑖\n",
       "|1⟩\t0.7071067811865476 + 0𝑖"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "()"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "DumpPlusState.simulate()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "> To learn more about the diagnostics features offered by Q# and the Quantum Development Kit, check out the [visualization sample](../../diagnostics/visualization/Visualizing%20Quantum%20Programs.ipynb)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The Q# package also allows you to capture these diagnostics and manipulate them as Python objects:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [],
   "source": [
    "with qsharp.capture_diagnostics() as diagnostics:\n",
    "    DumpPlusState.simulate()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[{'diagnostic_kind': 'state-vector',\n",
       "  'qubit_ids': [0],\n",
       "  'n_qubits': 1,\n",
       "  'amplitudes': {'0': {'Real': 0.7071067811865476,\n",
       "    'Imaginary': 0.0,\n",
       "    'Magnitude': 0.7071067811865476,\n",
       "    'Phase': 0.0},\n",
       "   '1': {'Real': 0.7071067811865476,\n",
       "    'Imaginary': 0.0,\n",
       "    'Magnitude': 0.7071067811865476,\n",
       "    'Phase': 0.0}}}]"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "diagnostics"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Working with raw JSON for diagnostics can be somewhat inconvienent, so the `capture_diagnostics` function also supports converting diagnostics into quantum objects using the QuTiP library:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [],
   "source": [
    "with qsharp.capture_diagnostics(as_qobj=True) as diagnostics:\n",
    "    DumpPlusState.simulate()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "Quantum object: dims = [[2], [1]], shape = (2, 1), type = ket\\begin{equation*}\\left(\\begin{array}{*{11}c}0.707\\\\0.707\\\\\\end{array}\\right)\\end{equation*}"
      ],
      "text/plain": [
       "Quantum object: dims = [[2], [1]], shape = (2, 1), type = ket\n",
       "Qobj data =\n",
       "[[0.70710678]\n",
       " [0.70710678]]"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "diagnostics[0]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Using other simulators"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Other simulators such as the Toffoli simulator, resources estimator, and open systems simulator are available as methods on the Python representations of Q# callables. For example, you can run Q# programs on the Toffoli simulator by using the `toffoli_simulate` method:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [],
   "source": [
    "%%qsharp\n",
    "open Microsoft.Quantum.Diagnostics;\n",
    "\n",
    "operation DumpOneState() : Unit {\n",
    "    use q = Qubit();\n",
    "    within {\n",
    "        X(q);\n",
    "    } apply {\n",
    "        DumpMachine();\n",
    "    }\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Offset  \tState Data\r\n",
      "========\t==========\r\n",
      "00000000\t1\r\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "()"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "DumpOneState.toffoli_simulate()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Similarly, the resources estimator can be used with the `estimate_resources()` method:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'CNOT': 1,\n",
       " 'QubitClifford': 1,\n",
       " 'R': 0,\n",
       " 'Measure': 2,\n",
       " 'T': 0,\n",
       " 'Depth': 0,\n",
       " 'Width': 2,\n",
       " 'QubitCount': 2,\n",
       " 'BorrowedWidth': 0}"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "PrepareAndMeasureBellPair.estimate_resources()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "To use the open systems simulator, you can use the `.simulate_noise` method:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/json": "{\"n_qubits\":3,\"data\":{\"Mixed\":{\"v\":1,\"dim\":[8,8],\"data\":[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[1,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]]}}}",
      "text/html": [
       "\r\n",
       "                <table>\r\n",
       "                    <caption>Mixed state</caption>\r\n",
       "                    <tr>\r\n",
       "                        <th># of qubits</th>\r\n",
       "                        <td>3</td>\r\n",
       "                    </tr>\r\n",
       "\r\n",
       "                    <tr>\r\n",
       "                        <th>State data</th>\r\n",
       "                        <td>\r\n",
       "                            $$\r\n",
       "                            \\left(\r\n",
       "                                \\begin{matrix}\r\n",
       "                                    0 + 0 i & 0 + 0 i & 0 + 0 i & 0 + 0 i & 0 + 0 i & 0 + 0 i & 0 + 0 i & 0 + 0 i\\\\\n",
       "0 + 0 i & 0 + 0 i & 0 + 0 i & 0 + 0 i & 0 + 0 i & 0 + 0 i & 0 + 0 i & 0 + 0 i\\\\\n",
       "0 + 0 i & 0 + 0 i & 0 + 0 i & 0 + 0 i & 0 + 0 i & 0 + 0 i & 0 + 0 i & 0 + 0 i\\\\\n",
       "0 + 0 i & 0 + 0 i & 0 + 0 i & 0 + 0 i & 0 + 0 i & 0 + 0 i & 0 + 0 i & 0 + 0 i\\\\\n",
       "0 + 0 i & 0 + 0 i & 0 + 0 i & 0 + 0 i & 1 + 0 i & 0 + 0 i & 0 + 0 i & 0 + 0 i\\\\\n",
       "0 + 0 i & 0 + 0 i & 0 + 0 i & 0 + 0 i & 0 + 0 i & 0 + 0 i & 0 + 0 i & 0 + 0 i\\\\\n",
       "0 + 0 i & 0 + 0 i & 0 + 0 i & 0 + 0 i & 0 + 0 i & 0 + 0 i & 0 + 0 i & 0 + 0 i\\\\\n",
       "0 + 0 i & 0 + 0 i & 0 + 0 i & 0 + 0 i & 0 + 0 i & 0 + 0 i & 0 + 0 i & 0 + 0 i\r\n",
       "                                \\end{matrix}\r\n",
       "                            \\right)\r\n",
       "                            $$\r\n",
       "                        </td>\r\n",
       "                    </tr>\r\n",
       "                </table>\r\n",
       "            "
      ],
      "text/plain": [
       "Mixed state on 3 qubits: [ [0 + 0 i, 0 + 0 i, 0 + 0 i, 0 + 0 i, 0 + 0 i, 0 + 0 i, 0 + 0 i, 0 + 0 i] [0 + 0 i, 0 + 0 i, 0 + 0 i, 0 + 0 i, 0 + 0 i, 0 + 0 i, 0 + 0 i, 0 + 0 i] [0 + 0 i, 0 + 0 i, 0 + 0 i, 0 + 0 i, 0 + 0 i, 0 + 0 i, 0 + 0 i, 0 + 0 i] [0 + 0 i, 0 + 0 i, 0 + 0 i, 0 + 0 i, 0 + 0 i, 0 + 0 i, 0 + 0 i, 0 + 0 i] [0 + 0 i, 0 + 0 i, 0 + 0 i, 0 + 0 i, 1 + 0 i, 0 + 0 i, 0 + 0 i, 0 + 0 i] [0 + 0 i, 0 + 0 i, 0 + 0 i, 0 + 0 i, 0 + 0 i, 0 + 0 i, 0 + 0 i, 0 + 0 i] [0 + 0 i, 0 + 0 i, 0 + 0 i, 0 + 0 i, 0 + 0 i, 0 + 0 i, 0 + 0 i, 0 + 0 i] [0 + 0 i, 0 + 0 i, 0 + 0 i, 0 + 0 i, 0 + 0 i, 0 + 0 i, 0 + 0 i, 0 + 0 i] ]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "()"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "DumpOneState.simulate_noise()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "> To learn more about using Q# and Python together, please see:\n",
    "> - [`qsharp` API reference](https://docs.microsoft.com/python/qsharp-core/qsharp)\n",
    ">\n",
    "> To learn more about using the open systems simulator, please see:\n",
    "> - [Process tomography sample](../../characterization/process-tomography/README.md)\n",
    "> - [Open systems simulator documentation](https://docs.microsoft.com/azure/quantum/machines/noise-simulator)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "interpreter": {
   "hash": "464ea5c5cae2889b0c59ecc40909802f0909ef10120e6598fbb774b74247ba9f"
  },
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
